﻿using System;
using System.ComponentModel;
using System.Runtime.InteropServices;
using System.Windows.Forms;
using Microsoft.VisualStudio.Shell;
using System.Drawing;
using VSTranslator.Translation;
using VSTranslator.Package;

namespace VSTranslator.Settings
{
	[Guid(GuidList.OptionsPageGuid)]
	[ComVisible(true)]
	public partial class OptionsPage : DialogPage//, System.Windows.Forms.IWin32Window
	{
		private OptionsPageControl OptionsControl;

		public OptionsPage()
		{
		//	InitializeComponent();
			TranslationService = "Google";
			SourceLanguage = "";
			TargetLanguage = "en";
		}

		[DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
		public string TranslationService { get; set; }
		[DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
		public string SourceLanguage { get; set; }
		[DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
		public string TargetLanguage { get; set; }
		
		[Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
		protected override IWin32Window Window
		{
			get
			{
				OptionsControl = new OptionsPageControl();
				OptionsControl.Location = new Point(0, 0);
				OptionsControl.OptionsPage = this;
				return OptionsControl;
			}
		}

		public override void SaveSettingsToStorage()
		{
			if (OptionsControl != null)
			{
				OptionsControl.UpdateOptions();
				Global.Options.Translator = TranslatorRegistry.GetTranslator(TranslationService);
				Global.Options.SourceLanguage = SourceLanguage;
				Global.Options.TargetLanguage = TargetLanguage;
				base.SaveSettingsToStorage();
			}
		}
	}
}
